package study.javabasic.Thread;

public class SynchronizedStudy implements Runnable {


    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        if (name.equals("a")) {
            asyan();
        } else if (name.equals("b")) {
            synblock1();
        } else if (name.equals("c")) {
            synmenthod1();
        }
    }

    private void synblock1() {
        synchronized (this){
            System.out.println(Thread.currentThread().getName()+"====start synblock1");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"====end synblock1");
        }

    }

    private synchronized void synmenthod1() {
        System.out.println(Thread.currentThread().getName()+"====start synmenthod1");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"====end synmenthod1");
    }

    private void asyan() {
        try {
            System.out.println(Thread.currentThread().getName()+"====start asyn");
            Thread.sleep(1000);

            System.out.println(Thread.currentThread().getName()+"====end asyn");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
